<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">节流提交</button>
    <script>
        function success() {
            console.log('提交成功');
        }

        // 节流函数
        const throttle = (fn, delay) => { // 1
            let flag = true; // 5
            return (...args) => { // 4
                if (!flag) return;
                flag = false; // 6
                setTimeout(() => { // 3
                    fn.apply(this, ...args);
                    flag = true; 
                }, delay);
            }
        }
        const oThrollte = throttle(success, 2000); // 2

        let btn = document.getElementById('btn');
        btn.addEventListener('click', oThrollte);
    </script>
</body>

</html>